package com.crux.kafka2ch.service;

import com.crux.kafka2ch.dto.AccessLogDto;
import com.crux.kafka2ch.event.AccessLogEvent;
import com.crux.kafka2ch.middleware.AccessLogStore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AccessLogServiceImpl implements AccessLogService {
    private final AccessLogStore accessLogStore;

    public AccessLogServiceImpl(AccessLogStore accessLogStore) {
        this.accessLogStore = accessLogStore;
    }

    @Override
    public void consumer(AccessLogDto accessLogDto) {
        accessLogStore.save(accessLogDto);
    }

    @EventListener
    public void onApplicationEvent(AccessLogEvent event) {
        accessLogStore.save(event.getAccessLogDto());
    }
}
